<?php
/**
 * Created by PhpStorm.
 * User: micoy
 * Date: 2018/12/14
 * Time: 1:30
 */

namespace app\admin\controller;



use think\Db;


/**
 * 底部链接管理
 * Class LinkController
 * @package app\admin\controller
 */
class LinkController extends AuthController {


    // 获得链接列表
    public function GetList() {

        $type = input('type', null);

        return Success('', Db::table('link')->select());

    }

    // 添加一个新链接
    public function Add() {

        $type = input('type');

        $data = input();

        $result = Db::table('link')->insert([
            'type'          => $data['type'],
            'title'         => $data['title'],
            'description'   => $data['description'],
            'url'           => $data['url'],
            'sort'          => 0,
        ]);

        if (!$result) {
            return Error('添加失败');
        }

        return Success();
    }

    // 删除一个链接
    public function Delete() {

        $result = Db::table('link')->where('id', input('id'))->delete();

        if (!$result) {
            return Error('删除失败');
        }

        return Success();

    }


}